package besta.moon.engine.table;

public class ForeignKeys {

    private int size;
    private ForeignKey[] data;

    public ForeignKeys() {
        data = new ForeignKey[16];
    }

    public final int size() {
        return size;
    }

    public final ForeignKey get(int idx) {
        if (idx >= size) {
            throw new IndexOutOfBoundsException("Column index: " + idx + ", Size: " + size);
        }
        return data[idx];
    }

    public final void add(ForeignKey foreignKey) {
        if (size >= data.length) {
            resize(size << 1);
        }
        data[size++] = foreignKey;
    }

    private void resize(int newSize) {
        ForeignKey[] dataNew = new ForeignKey[newSize];
        System.arraycopy(data, 0, dataNew, 0, size);
        data = dataNew;
    }
}
